
 int read_jpeg_file(const char *input_filename, const char *output_filename,int quality)  
 {  
         struct jpeg_decompress_struct cinfo;  
         struct jpeg_error_mgr jerr;  
         FILE *input_file;  
         FILE *output_file;  
         JSAMPARRAY buffer;  
         int row_width;  
         int row_width2; 
  
         unsigned char *output_buffer;  
         unsigned char *output_buffer2;  
         unsigned char *tmp = NULL;  
         unsigned char *tmp2 = NULL; 
  
         cinfo.err = jpeg_std_error(&jerr);  
  
         if ((input_file = fopen(input_filename, "rb")) == NULL) {  
                 fprintf(stderr, "can't open %s\n", input_filename);  
                 return -1;  
         }  
  
         if ((output_file = fopen(output_filename, "wb")) == NULL) {  
  
                fprintf(stderr, "can't open %s\n", output_filename);  
                 return -1;  
         }  
  
         // Initialization of JPEG compression objects  
         jpeg_create_decompress(&cinfo);  
  
         /* Specify data source for decompression */  
         jpeg_stdio_src(&cinfo, input_file);  
  
         /* 1.设置读取jpg文件头部，Read file header, set default decompression parameters */  
         (void) jpeg_read_header(&cinfo, TRUE);  
  
         /* 2.开始解码数据 Start decompressor */  
         (void) jpeg_start_decompress(&cinfo);  
  
         row_width = cinfo.output_width * cinfo.output_components;  
         row_width2 = cinfo.output_width ; 
  
         /* 3.跳过读取的头文件字节Make a one-row-high sample array that will go away when done with image */  
         buffer = (*cinfo.mem->alloc_sarray)  
                 ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_width, 1);  
  
         //write_bmp_header(&cinfo, output_file);  
  
         output_buffer = (unsigned char *)malloc(row_width * cinfo.output_height);  
         output_buffer2 = (unsigned char *)malloc(row_width2 * cinfo.output_height);  
         memset(output_buffer, 0, row_width * cinfo.output_height);  
         memset(output_buffer2, 0, row_width2 * cinfo